package com.dqhl.smartstable.util;

import android.app.Activity;
import android.app.Service;
import android.os.Vibrator;

/**
 * Created by mac on 16/10/20.
 */
public class VibratorUtil {

    /**
     * 一直震动多少秒
     *
     * @param activity
     * @param milliseconds
     */
    public static void Vibrate(final Activity activity, long milliseconds) {

        Vibrator vib = (Vibrator) activity

                .getSystemService(Service.VIBRATOR_SERVICE);

        vib.vibrate(milliseconds);

    }

    /**
     * 按照我们传进去的数组进行间歇性的震动
     *
     * @param activity
     * @param pattern
     * @param isRepeat
     */
    public static void Vibrate(final Activity activity, long[] pattern,

                               boolean isRepeat) {

        Vibrator vib = (Vibrator) activity

                .getSystemService(Service.VIBRATOR_SERVICE);

        vib.vibrate(pattern, isRepeat ? 1 : -1);

    }

    /**
     * 停止震动
     *
     * @param activity
     */
    public static void StopVibrate(final Activity activity) {

        Vibrator vib = (Vibrator) activity

                .getSystemService(Service.VIBRATOR_SERVICE);

        vib.cancel();

    }

}
